package com.jianguo.web.controller.user;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jianguo.common.annotation.Log;
import com.jianguo.common.core.controller.BaseController;
import com.jianguo.common.core.domain.AjaxResult;
import com.jianguo.common.enums.BusinessType;
import com.jianguo.user.domain.PzUserPatient;
import com.jianguo.user.service.IPzUserPatientService;
import com.jianguo.common.utils.poi.ExcelUtil;
import com.jianguo.common.core.page.TableDataInfo;

/**
 * 就诊人Controller
 *
 * @author xjj
 * @date 2024-03-21
 */
@RestController
@RequestMapping("/user/patient")
public class PzUserPatientController extends BaseController
{
    @Autowired
    private IPzUserPatientService pzUserPatientService;

    /**
     * 查询就诊人列表
     */
    @PreAuthorize("@ss.hasPermi('user:patient:list')")
    @GetMapping("/list")
    public TableDataInfo list(PzUserPatient pzUserPatient)
    {
        startPage();
        List<PzUserPatient> list = pzUserPatientService.selectPzUserPatientList(pzUserPatient);
        return getDataTable(list);
    }

    /**
     * 导出就诊人列表
     */
    @PreAuthorize("@ss.hasPermi('user:patient:export')")
    @Log(title = "就诊人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PzUserPatient pzUserPatient)
    {
        List<PzUserPatient> list = pzUserPatientService.selectPzUserPatientList(pzUserPatient);
        ExcelUtil<PzUserPatient> util = new ExcelUtil<PzUserPatient>(PzUserPatient.class);
        util.exportExcel(response, list, "就诊人数据");
    }

    /**
     * 获取就诊人详细信息
     */
    @PreAuthorize("@ss.hasPermi('user:patient:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(pzUserPatientService.getById(id));
    }

    /**
     * 新增就诊人
     */
    @PreAuthorize("@ss.hasPermi('user:patient:add')")
    @Log(title = "就诊人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PzUserPatient pzUserPatient) {
        return toAjax(pzUserPatientService.save(pzUserPatient));
    }

    /**
     * 修改就诊人
     */
    @PreAuthorize("@ss.hasPermi('user:patient:edit')")
    @Log(title = "就诊人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PzUserPatient pzUserPatient) {
        return toAjax(pzUserPatientService.updateById(pzUserPatient));
    }

    /**
     * 删除就诊人
     */
    @PreAuthorize("@ss.hasPermi('user:patient:remove')")
    @Log(title = "就诊人", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(pzUserPatientService.removeByIds(Arrays.asList(ids)));
    }
}
